﻿using PRO.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PRO.Common;
using PRO.Entity;
using PRO.Product;
using PRO.Config;
using Com.Alipay;

namespace web.payment
{
    public partial class payment : PageBase
    {
        private int id = CVGRequest.GetQueryString("id").DEC_Decode(BaseConfigs.DEC_KEY).ToInt(0);
        protected OrderInfo info = new OrderInfo();
        protected bool error = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "订单支付-" + BaseConfigs.Title;
            if (id == 0)
            {
                error = true;
                this.ErrorControl.Msg = "参数不正确！";
            }
            else
            {
                if (UserInfo.ID == 0)
                    Response.Redirect("/login?url=" + Request.RawUrl.UrlEncode());
                else
                {
                    Bind();
                }
            }
        }
        private void Bind()
        {
            info = OrderLib.GetOrderInfo(id, UserInfo.ID);
            if (info.Status == 1)
            {
                error = true;
                this.ErrorControl.Msg = "该订单已经支付过了！";
            }
            else if (info.Status == -1)
            {
                error = true;
                this.ErrorControl.Msg = "订单已经取消！";
            }
            else if (info.Status == 0)
            {
                if (info.ID != 0)
                {
                    List<OrderItemInfo> items = OrderLib.GetOrderItems(info.ID);
                    this.Repeater1.DataSource = items;
                    this.Repeater1.DataBind();
                }
            }
            else
            {
                error = true;
            }
        }

        protected void Button_PayMent_Click(object sender, EventArgs e)
        {
            ParamInfo info=new ParamInfo();
            AlipayLib.SubmitPay(info);
        }
    }
}